import 'package:flutter/material.dart';

class Home extends StatelessWidget {
  const Home({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Button Demo"),
        actions: [IconButton(onPressed: () {}, icon: Icon(Icons.share))],
      ),
      body: ButtonDemo(),
    );
  }
}

// TextButton : 普通按钮
// ElevatedButton: 漂浮按钮，它默认带有阴影和灰色背景。按下后，阴影会变大
// OutlinedButton : 轮廓按钮
// IconButton : 图标按钮

class ButtonDemo extends StatelessWidget {
  const ButtonDemo({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.all(20),
      child: Wrap(
        direction: Axis.vertical,
        children: [
          TextButton(
              onPressed: () {
                print("点击 TextButton");
              },
              child: Text("TextButton")),
          ElevatedButton(
              onPressed: () {
                print("点击 ElevatedButton");
              },
              onLongPress: () {
                print("长按 ElevatedButton");
              },
              child: Text("ElevatedButton")),
          OutlinedButton(
            onPressed: () {
              print("点击 轮廓按钮");
            },
            child: Text("轮廓按钮"),

            //按钮样式
            style: ButtonStyle(
                backgroundColor: MaterialStateProperty.all(Colors.black),
                foregroundColor: MaterialStateProperty.resolveWith((states) {
                  if (states.contains(MaterialState.pressed)) {
                    return Colors.red;
                  }
                  return Colors.white;
                }),
                //文本样式
                textStyle: MaterialStateProperty.all(TextStyle(fontSize: 30)),
                //阴影
                shadowColor: MaterialStateProperty.all(Colors.red),
                elevation: MaterialStateProperty.all(5),

                //按钮的形状
                shape: MaterialStateProperty.all(StadiumBorder(
                    side: BorderSide(width: 2, color: Colors.green))),

                //尺寸
                minimumSize: MaterialStateProperty.all(Size(200, 100))
                
              ),
          ),
          IconButton(
              onPressed: () {
                print("icon 按钮");
              },
              icon: Icon(Icons.thumb_up))
        ],
      ),
    );
  }
}
